package com.ruoyi.web.controller.construction.supertube;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderMaster;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderVoucher;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderMasterService;
import com.ruoyi.system.service.zhaungxiuservice.shopService.OrderVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/super/offlineOrder")
public class OfflineOrderController extends BaseController {


    @Autowired
    private OrderMasterService orderMasterService;

    @Autowired
    private OrderVoucherService orderVoucherService;



    @PreAuthorize("@ss.hasPermi('super:offlineOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderMaster orderMaster){
        startPage();
        List<OrderMaster> orderMasterList = this.orderMasterService.selectOfflineOrderMaster(orderMaster);
        for (int i = 0; i < orderMasterList.size(); i++) {
            orderMasterList.get(i).setAddress1(orderMasterList.get(i).getProvince()+orderMasterList.get(i).getCity()+orderMasterList.get(i).getDistrict()+orderMasterList.get(i).getAddress());
        }
        return getDataTable(orderMasterList);
    }

    @GetMapping("/updateOrderVoucher/{orderVoucherId}")
    public AjaxResult updateOrderVoucher(@PathVariable(value = "orderVoucherId", required = false) Long orderVoucherId){
        System.out.println("=====orderVoucherId:"+orderVoucherId);
        OrderVoucher orderVoucher = this.orderVoucherService.selectOrderVoucherById(orderVoucherId);
        OrderMaster orderMaster = this.orderMasterService.selectOrderMasterById(orderVoucher.getOrderMasterId().intValue());
        orderMaster.setOrderStatus(2);
        this.orderMasterService.updateOrderMaster(orderMaster);
        orderVoucher.setOrderVoucherId(orderVoucherId);
        orderVoucher.setVoucherType("1");
        return toAjax(this.orderVoucherService.updateOrderVoucher(orderVoucher));
    }
}
